﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NGinnBPM.Runtime.Messages;
using NGinnBPM.Lib.Data;
using NGinnBPM.Lib.Interfaces;
using NLog;
using System.Runtime.Serialization;

namespace NGinnBPM.Runtime.Tasks
{
    /// <summary>
    /// External task can be used when the task logic is elsewhere. This task sends 'ExternalTaskEnabled' message
    /// when it's enabled and waits for response, which should be one of
    /// - ForceCompleteTaskMessage
    /// - FailTaskMessage
    /// - CancelTaskMessage
    /// The actual task logic should be implemented in the handler of ExternalTaskEnabled message.
    /// Now there's a question which handler should get the ExternalTaskEnabled message if there are several different
    /// external tasks used. The answer is they will all get the message and have to decide if they should handle it or not
    /// </summary>
    [Serializable]
    [DataContract]
    public class ExternalTaskInstance : AtomicTaskInstance
    {
        /// <summary>
        /// Endpoint where the ExternalTaskEnabled message will be sent.
        /// </summary>
        [DataMember]
        public string HandlerEndpoint { get; set; }

        public override void Enable(Dictionary<string, object> inputData)
        {
            base.Enable(inputData);
            ExternalTaskEnabled ete = new ExternalTaskEnabled();
            Context.MessageBus.Send(HandlerEndpoint, ete);
        }


    }
}
